﻿function ClientAddWebLink(WebLinkId)
{
    belongSite = document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    Url = SODC.CMPortal.WebLink.WebLinkWP.GetAddGroupNewUrl(belongSite).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //FilterFunc();
}

function ClientSaveWebLink()
{
    belongSite=document.getElementById("txtBelongSite").value;
    WebName = document.getElementById("txtWebName").value;
    WebUrl = document.getElementById("txtWeburl").value;

    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    RetValue = SODC.CMPortal.AddWebLinkWP.ServerSideAddWebLink(belongSite,language,WebName,WebUrl).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientDeleteWebLink(WebId)
{
    Msg=SODC.CMPortal.WebLink.WebLinkWP.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = SODC.CMPortal.WebLink.WebLinkWP.ServerSideDeleteWebLink(WebId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc();
}

function ShowClientUpdateUrlForm(WebLinkId)
{
    Url=SODC.CMPortal.WebLink.WebLinkWP.GetShowUpdateForm(WebLinkId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 768px; dialogWidth: 1024px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    FilterFunc();
}

function SaveUpdateFAQ(AskID)
{
    AskAnswer = document.getElementById("txtAnswer").value;
    if(document.getElementById("chkStatus").value!=null)
    AskStatus = true;
    
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    RetValue = SODC.CMPortal.FAQ.UpdateFAskQuestions.ServerSideUpdateFAQ(language,AskID,AskAnswer,AskStatus).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ShowClientOnlineSupportItemUrlForm(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetShowOnlineSupportItemsForm(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function ClientShowAddOnlineSupportItemRootForm(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetAddOnlineSupportItemFormUrl(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientShowAddOnlineSupportItemSubForm(OnlineSupportId,ParentOnlineSupportItemId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetAddSubOnlineSupportItemFormUrl(OnlineSupportId,ParentOnlineSupportItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}



function ClientShowUpdateOnlineSupportItemSubForm(OnlineSupportId,OnlineSupportItemId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetUpdateSubOnlineSupportItemFormUrl(OnlineSupportId,OnlineSupportItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientSaveAddOnlineSupportItem(OnlineSupportId)
{
    MaxItems=document.getElementById("txtMaxItems").value;
    SaveItems=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.CreateSaveItemsObject(MaxItems).value;
    for(var Index=0;Index<SaveItems.length;Index++)
    {
        SaveItems[Index].Title=document.getElementById("txtTitle_"+Index).value;
        SaveItems[Index].Checked=document.getElementById("checkBox_"+Index).checked;
        SaveItems[Index].IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        SaveItems[Index].AdvImageId = document.getElementById("txtAdvImageId_"+Index).value;
    }
    
    
    retValue=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.ServerSideAddOnlineSupportItems(OnlineSupportId,SaveItems).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    window.close();
}

function DeleteOnlineSupportItem(OnlineSupportId,OnlineSupportIdItemId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetConfirmMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideDeleteOnlineSupportItem(OnlineSupportIdItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue);
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientSaveOnlineSupportItem(OnlineSupportId,OnlineSupportItemId)
{
    OnlineSupportItemName=document.getElementById("txtOnlineSupportItemName").value;
    IndexOrder=document.getElementById("txtIndexOrder").value;
    retValue=SharepointPortal.WebParts.OnlineSupport.UpdateOnlineSupportItem.ServerSideOnlineSupportItem(OnlineSupportItemId,OnlineSupportItemName,IndexOrder).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.close();
}

function ClientShowNewsItemForms(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetShowNewsItemForm(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function DetectAdvImageItem()
{
    selectedIndex=document.getElementById("divSelectAdvImage").selectedIndex;
    AdvImageId=document.getElementById("divSelectAdvImage").options[selectedIndex].value;
    value=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.GetAdvImageText(AdvImageId).value;
    document.getElementById("divContentAdvImage").innerHTML=value;
}

function ClientSaveOnlineSupportItems()
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Max=document.getElementById("txtMaxItems").value;
    for(var Index=0;Index<Max;Index++)
    {
        Id=document.getElementById("txtId_"+Index).value;
        Subject=document.getElementById("txtSubject_"+Index).value;
        IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        
        SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideSaveOnlineSupportItem(language,Id,Subject,IndexOrder).value;
    }   
    alert(SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideGetSaveOkMsg().value);
}


function DetectHtmlBody(OnlineSupportId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divContentData").innerHTML=retValue;
}


function DetectUpdateOnlineSupportBody(OnlineSupportId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=SharepointPortal.WebParts.OnlineSupport.UpdateOnlineSupport.GetSubject(language,OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("txtOnlineSupport").innerHTML=retValue;
}

function ClientPublishing(OnlineSupportId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetProcessingText().value;
    setTimeout("RealClientPublishing('"+OnlineSupportId+"')",10);
}

function RealClientPublishing(OnlineSupportId)
{
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.ServerSidePublishing(OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}

function PublishingOnlineSupportItem(OnlineSupportItemId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetProcessingText().value;
 
    setTimeout("RealPublishingOnlineSupportItem('"+OnlineSupportItemId+"')",10);
}

function RealPublishingOnlineSupportItem(OnlineSupportItemId)
{
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideItemPublishing(OnlineSupportItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}




function FilterFunc()
{
    document.getElementById("divProcessing").innerHTML=SODC.CMPortal.WebLink.WebLinkWP.GetProcessingText().value;
    setTimeout("RealFilterFunc()",10);
}


function RealFilterFunc()
{
    belongSite=document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    retValue= SODC.CMPortal.FAQ.FAskQuestionsWP.GetHtml(belongSite).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divOnlineSupportMain").innerHTML=retValue;
}